#include "SettingModel.h"
const std::string SettingModel::s_settingConfPath = "setting.xml";

SettingModel::SettingModel()
{
    readSettingConfFromFile();
}

const SettingConf& SettingModel::getSettingConf() const
{
    return m_settingConf;
}

void SettingModel::readSettingConfFromFile()
{
    if (!m_settingConf.loadXmlFromFile(s_settingConfPath))
    {
        m_settingConf.SessionType = SessionType::SHAANXI;
        m_settingConf.CanChi = true;
        m_settingConf.CanPeng = true;
        m_settingConf.CanGang = true;
        m_settingConf.CanHu = true;
        saveSettingConf2File(m_settingConf);
    }
}

bool SettingModel::saveSettingConf2File(const SettingConf& settingConf)
{
    m_settingConf = settingConf;
    FILE* saveFile = fopen(SettingModel::s_settingConfPath.c_str(), "wb");
    if (saveFile)
    {
        fputs(m_settingConf.getXml().c_str(), saveFile);
        fclose(saveFile);
        saveFile = nullptr;
    }
    return false;
}
